#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

class Solution {
public:
  int maxTurbulenceSize(vector<int> &arr) {
    if (arr.size() == 1) {
      return 1;
    }

    if ((arr.size() == 2) && (arr[0] != arr[1])) {
      return 2;
    } else if (arr.size() == 2) {
      return 1;
    }

    int res = 0;
    int left = 0;
    int right = 2;
    long long int flags = arr[1] - arr[0];
    while (right < arr.size()) {
      if ((arr[right] - arr[right - 1] < 0) && (flags > 0)) {
        flags = arr[right] - arr[right - 1];
        res = max(res, right - left + 1);
        ++right;
      } else if ((arr[right] - arr[right - 1] > 0) && (flags < 0)) {
        flags = arr[right] - arr[right - 1];
        res = max(res, right - left + 1);
        ++right;
      } else {
        if ((flags == 0) && (arr[right] != arr[right - 1])) {
          res = max(res, 2);
        } else if ((flags == 0) && (arr[right] == arr[right - 1])) {
          res = max(res, 1);
        } else {
          res = max(res, 2);
        }
        left = right - 1;
        flags = arr[right] - arr[left];
        ++right;
      }
    }
    return res;
  }
};

int main() {
  std::vector<int> a = {0, 1, 1, 0, 1, 0, 1, 1, 0, 0};
  cout << Solution().maxTurbulenceSize(a) << endl;
}
